package com.xaicode.template.async.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author Locker
 * @date 2021/8/4 0004 11:09
 */
@Slf4j
public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {
    @Override
    public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
        log.error("Async method has uncaught exception, params:{}" + Arrays.toString(objects));

        if (throwable instanceof AsyncException) {
            AsyncException asyncException = (AsyncException) throwable;
            log.error("asyncException:"  + asyncException.getMessage());
        }

        log.error("Exception :", throwable);
    }
}
